package com.spring.demo.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.spring.demo.domain.mongodb.History;
import com.spring.demo.repository.mongodb.HistoryCRUD;
import com.spring.demo.repository.mongodb.HistoryRepository;

@Service
@Transactional(readOnly = true)
public class HistoryServiceImpl implements HistoryService {

	@Autowired
	private HistoryRepository historyRepository;
	
	@Autowired
	private HistoryCRUD historyCRUD;
	
	@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)
	public void saveHistory(History history) {
		historyRepository.save(history);
	}
	
	public List<History> findAll() {
		return historyRepository.findAll();
	}
	
	@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)
	public void insertHistory(History history) {
		historyCRUD.insertHistory(history);
	}
}
